package com.liuyk.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class PathView extends View {
    private Paint mPain;

    public PathView(Context context) {
        this(context, null);
    }

    public PathView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPain = new Paint();
        mPain.setStrokeWidth(3f);
        mPain.setColor(Color.RED);
        mPain.setAntiAlias(true);
        mPain.setDither(true);
        mPain.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Path path = new Path();
        path.moveTo(40, 40);
        path.lineTo(340, 340);
        path.quadTo(90, 540, 340, 740);
        path.cubicTo(640, 640, 540, 290, 90, 840);
        path.quadTo(540, 40, 40, 40);
        canvas.drawPath(path, mPain);
    }
}
